﻿using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace IceDog.JsonDotNet.Model.NewJsonConverter
{
    public class VersionConverter : JsonConverter<Version>
    {
        public override Version ReadJson(JsonReader reader, Type objectType, [AllowNull] Version existingValue, bool hasExistingValue, JsonSerializer serializer)
        {
            //把字符串转换为对象
            string s = (string)reader.Value;
            return new Version(s);
        }

        public override void WriteJson(JsonWriter writer, [AllowNull] Version value, JsonSerializer serializer)
        {
            //把对象转换为字符串
            writer.WriteValue(value.ToString());
        }
    }
}
